#!/usr/bin/env python3

from __future__ import print_function
from ctypes import CDLL
import sys

def help():
    print("""
Usage: m lock [options]

Options:
  --help      Show this help message and exit
""")
    sys.exit()

def lock():
    path = '/System/Library/PrivateFrameworks/login.framework/Versions/Current/login'
    try:
        login = CDLL(path)
        login.SACLockScreenImmediate()
    except OSError:
        print("Couldn't load framework: ", path)
    except AttributeError:
        print("Function is not available.")

def main(args):
    if '--help' in args:
        help()
        sys.exit(0)

    if len(args) > 0:
        help()
        sys.exit(1)

    lock()


if __name__ == "__main__":
    main(sys.argv[1:])
